package com.weaver.teams;

import sun.misc.ProxyGenerator;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

public class DynamicProxy {
    public static void main(String[] args) {
        InvocationHandler myInvocationHandler = new MyInvocationHandler(new DynamicProxy());
        Class<?>[] interfaces = Woman.class.getInterfaces();
        Man o = (Man) Proxy.newProxyInstance(DynamicProxy.class.getClassLoader(), interfaces, myInvocationHandler);
        o.say();





        byte[] proxyClassFile = ProxyGenerator.generateProxyClass(
                "aaaaa", interfaces);
        File file = new File("c:/a.class");
        try {
            OutputStream outputStream = new FileOutputStream(file);
            outputStream.write(proxyClassFile);
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
